<template>
  <div>
    <input
      type="text"
      v-model="taskText"
      placeholder="输入任务"
      @keypress.enter="addTask"
    />
    <button @click="addTask">添加</button>
  </div>
</template>

<script setup>
import { ref } from 'vue';
const taskText = ref('');
const emit = defineEmits(['addTask']);

const addTask = () => {
  if (taskText.value.trim()) {
    emit('addTask', taskText.value);
    taskText.value = '';
  }
};
</script>